package com.example.sxproject.mapper;

import com.example.sxproject.pojo.Card;
import com.example.sxproject.pojo.FPSearch;
import com.example.sxproject.pojo.FinancialProduct;
import com.example.sxproject.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //根据用户名查询用户
    @Select("select * from user where phone=#{phone}")
    User findByPhone(String phone);

    //添加
    @Insert("insert into user (phone, password, userType)"+
    " values(#{phone}, #{password}, #{userType})")
    void add(String phone, String password, Integer userType);

    //根据用户号查询是否存在
    @Select("select * from user where houseNumber=#{houseNumber}")
    User findByHouseNumber(String houseNumber);

    @Select({
            "<script>",
            "SELECT *",
            "FROM user",
            "<where>",
            "<if test='id!= null'>",
            "id=#{id}",
            "</if>",
            "<if test='phone!= null'>",
            "AND phone = #{phone}",
            "</if>",
            "<if test='cardId != null'>",
            "AND cardId = #{cardId}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<User> SelectUser(User user);


    @Insert("insert into user(realName,birthday,sex,cardId,address,phone,mail,password,userType,userStatus,houseNumber) "+
    "values(#{realName},#{birthday},#{sex},#{cardId},#{address},#{phone},#{mail},#{password},#{userType},#{userStatus},#{houseNumber}) ")
    void addUserMessage(User user);

    //查全部
    @Select("select * from user")
    List<User> selectAll();

    //修改用户个人信息

    @Update("UPDATE user SET " +
            "realName = #{realName}, " +
            "birthday = #{birthday}, " +
            "sex = #{sex}, " +
            "cardId = #{cardId}, " +
            "address = #{address}, " +
            "mail = #{mail}, " +
            "photo = #{photo}, " +
            "houseNumber = #{houseNumber} " +
            "WHERE phone = #{phone}")
    void updateInformation(User user);

    //更改登录密码
    @Update("UPDATE user SET password=#{password} WHERE phone=#{phone}")
    void changePassword(String phone, String password);

    //更新：实现用户假删除
    @Update("UPDATE user SET userStatus='2' WHERE id=#{id}")
    void deleteUser(Integer id);

    @Update("UPDATE user SET " +
            "realName = #{realName}, " +
            "birthday = #{birthday}, " +
            "sex = #{sex}, " +
            "cardId = #{cardId}, " +
            "address = #{address}, " +
            "phone = #{phone}, " +
            "mail = #{mail}, " +
            "password = #{password}, " +
            "creditScore = #{creditScore}, " +
            "userType = #{userType}, " +
            "photo = #{photo}, " +
            "userStatus = #{userStatus} " +
           /* "houseNumber = #{houseNumber}," +*/
            "WHERE id = #{id}")
    void userMessageUpdate(User user);

    //真删除
    @Delete("DELETE FROM user WHERE id=#{id}")
    void userMessageDel(Integer id);
}
